package com.nj.swagger.conf;

import com.nj.swagger.bean.SwaggerBean;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configurable
public class Swagger3Config {
    @Autowired
    private SwaggerBean swaggerBean;
    @Bean
    public Docket apiConfig(){
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .select()
                //设置通过什么方式定位到需要生成文档的接口.
                //定位了方法上的ApiOperation
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //接口URL路径，any表示全部的路径 .regex("/student/*")
                .paths(PathSelectors.any())
                .build();
    }
    @Bean
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(swaggerBean.getTitle())
                .description(swaggerBean.getDescription())
                .contact(new Contact(swaggerBean.getContactName(), swaggerBean.getContactUrl(), swaggerBean.getContactEmail()))
                .version(swaggerBean.getVersion())
                .build();
    }
}
